﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Reflection;

namespace SharePointBrowser
{
    internal class Configuration
    {
        private static Configuration instance = new Configuration();

        private bool showHiddenLists;

        public bool ShowHiddenLists
        {
            get { return showHiddenLists; }
            set { showHiddenLists = value; }
        }

        public static Configuration Instance
        {
            get { return instance; }
        }

        private Configuration()
        {
            Load();
        }

        public void Load()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName + ".config");
            XmlNode showHiddenListsSetting = xmlDoc.SelectSingleNode("appSettings/add[@key='ShowHiddenLists']");
            showHiddenLists = Convert.ToBoolean(showHiddenListsSetting.Attributes["value"].Value);
        }

        public void Save()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName + ".config");
            XmlNode showHiddenListsSetting = xmlDoc.SelectSingleNode("appSettings/add[@key='ShowHiddenLists']");
            showHiddenListsSetting.Attributes["value"].Value = showHiddenLists.ToString();
            xmlDoc.Save(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName + ".config");
        }
    }
}
